package com.panfeng.xcloud.boss.provider.assets.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.panfeng.xcloud.boss.provider.assets.dto.request.QueryRebateRecordPageReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.request.RebateDetailReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.QueryRebateRecordPageRespDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.RebateDetailRespDTO;
import com.panfeng.xcloud.boss.provider.assets.service.IRebateRecordService;
import com.panfeng.xcloud.boss.provider.assets.web.vo.request.QueryRebateRecordPageReqVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.request.RebateDetailReqVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.response.QueryRebateRecordPageRespVO;
import com.panfeng.xcloud.boss.provider.assets.web.vo.response.RebateDetailRespVO;
import com.panfeng.xcloud.common.core.page.PageResponse;
import com.panfeng.xcloud.common.core.utils.ConvertUtils;
import com.panfeng.xcloud.common.core.web.vo.PageResponseVO;
import com.panfeng.xcloud.common.core.web.vo.ResponseVO;
import com.panfeng.xcloud.common.security.annotation.MethodValidate;
import com.panfeng.xcloud.common.security.annotation.NotNeedAccess;
import com.panfeng.xcloud.common.security.web.support.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 返佣记录模块
 *
 * @author xiaobo
 * @version 1.0
 * @since 2024-05-02
 */
//@ApiIgnore
@RestController
@RequestMapping("assets/rebateRecord")
@Api(tags = {"返佣记录模块"})
@Slf4j
public class RebateRecordController extends BaseController {

    @Autowired
    private IRebateRecordService iRebateRecordService;

    /**
     * 查询相关返佣记录
     *
     * @param queryRebateRecordPageReqVO
     * @param bindingResult
     * @return
     */
    @NotNeedAccess
    @MethodValidate
    @PostMapping(value = "/queryRebateRecord", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询相关返佣记录(肖博)", httpMethod = "POST", notes = "查询相关返佣记录(肖博)")
    public ResponseVO<PageResponseVO<QueryRebateRecordPageRespVO>> queryRebateRecord(@RequestBody @Valid QueryRebateRecordPageReqVO queryRebateRecordPageReqVO, BindingResult bindingResult) {
        logger.info(">>>> 当前queryRebateRecord请求参数：{} <<<", (null != queryRebateRecordPageReqVO ? JSONObject.toJSONString(queryRebateRecordPageReqVO) : ""));
        QueryRebateRecordPageReqDTO queryRebateRecordPageReqDTO = ConvertUtils.convert(queryRebateRecordPageReqVO, QueryRebateRecordPageReqDTO.class);
        PageResponse<QueryRebateRecordPageRespDTO> pageDTO = iRebateRecordService.queryRebateRecord(queryRebateRecordPageReqDTO);
        PageResponseVO<QueryRebateRecordPageRespVO> pageVO = ConvertUtils.convertPage(pageDTO, QueryRebateRecordPageRespVO.class);
        logger.info(">>>> 当前queryRebateRecord响应内容：{} <<<", (null != pageVO ? JSONObject.toJSONString(pageVO) : ""));
        return ResponseVO.with(pageVO);
    }

    /**
     * 查询相关返佣信息
     *
     * @param rebateDetailReqVO
     * @param bindingResult
     * @return
     */
    @NotNeedAccess
    @MethodValidate
    @PostMapping(value = "/rebateDetail", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询相关返佣信息", httpMethod = "POST", notes = "查询相关返佣信息")
    public ResponseVO<RebateDetailRespVO> rebateDetail(@RequestBody @Valid RebateDetailReqVO rebateDetailReqVO, BindingResult bindingResult) {
        log.info(">>>> 当前rebateDetail请求参数：{} <<<", (null != rebateDetailReqVO ? JSONObject.toJSONString(rebateDetailReqVO) : ""));
        RebateDetailReqDTO rebateDetailReqDTO = ConvertUtils.convert(rebateDetailReqVO, RebateDetailReqDTO.class);
        RebateDetailRespDTO rebateDetailRespDTO = iRebateRecordService.rebateDetail(rebateDetailReqDTO);
        RebateDetailRespVO rebateDetailRespVO = ConvertUtils.convert(rebateDetailRespDTO, RebateDetailRespVO.class);
        log.info(">>>> 当前rebateDetail响应内容：{} <<<", (null != rebateDetailRespVO ? JSONObject.toJSONString(rebateDetailRespVO) : ""));
        return ResponseVO.with(rebateDetailRespVO);
    }

}
